package com.siwei.mes.entity.materials;

import cn.dev33.satoken.stp.StpUtil;
import com.siwei.mes.common.validator.AddGroup;
import com.siwei.mes.common.validator.UpdateGroup;
import com.siwei.mes.config.UidUtils;
import com.siwei.mes.enums.GenerateCodeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
import java.util.List;


/**
 * 材料及规格配置(MaterialsSpecConfig)实体类
 *
 * @author linzi
 * @since 2024-05-18 23:33:00
 */
@Data
@Accessors(chain = true)
@Table(name = "pk_materials_spec_config")
@ApiModel(value = "MaterialsSpecConfig", description = "材料及规格配置")
public class MaterialsSpecConfig implements Serializable {
    private static final long serialVersionUID = 192966437228242031L;
    /**
     * 主键id
     */
    @Id
    @ApiModelProperty(value = "材料及规格配置主键ID", name = "id")
    @NotNull(groups = {UpdateGroup.class}, message = "材料及规格配置主键id为空")
    private Long id;
    /**
     * 材料编号
     */
    @Column(name = "materials_no")
    @ApiModelProperty(value = "材料编号", name = "materialsNo")
    private String materialsNo;
    /**
     * 材料类型 1-水泥 2-粉煤灰 3-矿渣粉 4-粗骨料 5-细骨料 6-外加剂 7-混凝土
     */
    @Column(name = "materials_type")
    @NotNull(groups = {AddGroup.class, UpdateGroup.class}, message = "材料类型为空")
    @ApiModelProperty(value = "材料类型", name = "materialsType")
    private Integer materialsType;
    /**
     * 材料名称
     */
    @Column(name = "materials_name")
    @ApiModelProperty(value = "材料名称", name = "materialsName")
    @NotBlank(groups = {AddGroup.class, UpdateGroup.class}, message = "材料名称为空")
    private String materialsName;

    @Column(name = "material_abbreviation")
    @ApiModelProperty(value = "物料简称")
    private String materialAbbreviation;

    /**
     * 材料规格
     */
    @Column(name = "materials_spec")
    @ApiModelProperty(value = "材料规格", name = "materialsSpec")
    @NotBlank(groups = {AddGroup.class, UpdateGroup.class}, message = "材料规格为空")
    private String materialsSpec;
    /**
     * 创建人
     */
    @Column(name = "creater")
    @ApiModelProperty(value = "创建人", name = "creater")
    private Long creater;
    /**
     * 创建时间
     */
    @Column(name = "create_time")
    @ApiModelProperty(value = "创建时间", name = "createTime")
    private Date createTime;
    /**
     * 修改人
     */
    @Column(name = "updater")
    @ApiModelProperty(value = "修改人", name = "updater")
    private Long updater;
    /**
     * 更新时间
     */
    @Column(name = "update_time")
    @ApiModelProperty(value = "更新时间", name = "updateTime")
    private Date updateTime;
    /**
     * 是否删除  1-删除
     */
    @Column(name = "is_del")
    @ApiModelProperty(value = "是否删除  1-删除", name = "isDel")
    private Integer isDel;

    @Column(name = "is_laboratory")
    @ApiModelProperty(value = "是否同步的协会  1-是  0-不是")
    private Integer isLaboratory;

    @Column(name = "sample_id")
    @ApiModelProperty(value = "协会sampleId")
    private String sampleId;

    @Column(name = "sample_name")
    @ApiModelProperty(value = "协会sampleName")
    private String sampleName;

    @Column(name = "spec_id")
    @ApiModelProperty(value = "协会specId")
    private String specId;

    @Column(name = "spec_name")
    @ApiModelProperty(value = "协会specName")
    private String specName;

    @Column(name = "grade_id")
    @ApiModelProperty(value = "协会gtadeId")
    private String gradeId;

    @Column(name = "grade_name")
    @ApiModelProperty(value = "协会gradeName")
    private String gradeName;

    @Column(name = "sample_judge")
    @ApiModelProperty(value = "协会试验依据")
    private String sampleJudge;

    @Transient
    @ApiModelProperty(value = "多个材料类型")
    private List<String> materialsTypeList;

    public MaterialsSpecConfig init(boolean isCreate) {
        this.setUpdater(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null)
                .setUpdateTime(new Date());
        if (isCreate) {
            this.setCreater(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null)
                    .setCreateTime(new Date())
                    .setIsDel(0).setMaterialsNo(UidUtils.genNo(GenerateCodeEnum.MATERIALS_SPEC_CONFIG.getCode()));
        }
        return this;
    }
}
